package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMateriaDto;
import com.heima.wemedia.service.WmMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author 10161
 */
@RestController
@RequestMapping("/api/v1/material")
public class MaterialController {
    @Autowired
    private WmMaterialService wmMaterialService;

    /**
     * 图片上传
     *
     * @param multipartFile
     * @return
     * @throws IOException
     */
    @PostMapping("/upload_picture")
    public ResponseResult uploadPicture(MultipartFile multipartFile) throws IOException {
        return wmMaterialService.uploadPicture(multipartFile);
    }

    /**
     * 查询素材列表展示
     *
     * @param wmMateriaDto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult getList(@RequestBody WmMateriaDto wmMateriaDto) {
        return wmMaterialService.getList(wmMateriaDto);
    }

    /**
     * 删除素材
     * @param id
     * @return
     */
    @GetMapping("/del_picture/{id}")
    public ResponseResult deletePicture(@PathVariable Integer id) {
        return wmMaterialService.deletePicture(id);
    }

    @GetMapping("/collect/{id}")
    public ResponseResult collect(@PathVariable Integer id){
        return wmMaterialService.collect(id);
    }

    /**
     * 取消收藏
     * @param id
     * @return
     */
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancelCollect(@PathVariable Integer id){
        return wmMaterialService.cancelCollect(id);
    }

}
